// const baseUrl = 'http://192.168.1.109:8010'
function fetchRequest (url = '', method = 'GET', data = {}) {
  const stream = weex.requireModule('stream')
  const fetchUrl = url// baseUrl + url
  return new Promise((resolve, reject) => {
    stream.fetch({
      method: method,
      url: fetchUrl,
      headers: {
        'Content-Type': 'application/json',
        'weex': 'true'
      },
      type: 'json',
      body: method === 'GET' ? '' : data
    }, (response) => {
      if (response.status === 200 || response.status === 201 || response.status === 204 || response.status === 202) {
        resolve(response)
      } else {
        reject(response)
      }
    }, () => {
    })
  })
  // console.log('fetch1')
  // const fetchCfg = {
  //   method, // *GET, POST, PUT, DELETE, etc.
  //   mode: 'cors', // no-cors, *cors, same-origin
  //   cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
  //   credentials: 'same-origin', // include, *same-origin, omit
  //   headers: {
  //     'Content-Type': 'application/json'
  //     // 'Content-Type': 'application/x-www-form-urlencoded',
  //   },
  //   redirect: 'follow', // manual, *follow, error
  //   referrerPolicy: 'no-referrer' // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
  //   // body: JSON.stringify(data) // body data type must match "Content-Type" header
  // }
  // if (method === 'POST') {
  //   fetchCfg['body'] = JSON.stringify(data)
  // }
  // const fetchUrl = baseUrl + url
  // // Default options are marked with *
  // const response = fetch(fetchUrl, fetchCfg)
  // return response // parses JSON response into native JavaScript objects
}
export {fetchRequest}
